<?php
/**
 * Implement command WNavigator/getPage
 * <pre>
 * Arguments:
 * 1. path (string, mandatory)
 *    Path to the page 
 * 2. extend (boolean, optional) 
 *    Return full pages subtree or not. Default value "false".
 * Result:
 * Data structure   
 * page
 * |-name
 * |-meta [uri]
 * | |-<value>+
 * |-content
 * |-children
 * | |-page+
 * </pre>
 * @package WNavigator
 * 
 */
require_once 'WKernel/Command/Abstract.php';
class WN_Cmd_getPage extends WK_Command_Abstract {
	public function __construct(){
		parent::__construct();
		$this->params['expand'] = 0;
	}
	
	public function exec() {
		$nav  = WK_Application::getComponent('WNavigator');		
		$page = $nav->getMap()->getPage($this->params['path']);			
		if(empty($page)){
			throw WK_Application::getException(404, 'Page not found');				
		}
		else {
			$page->expandMeta();
			$this->result = $page->toData($this->params['expand']);
		}			
	}	
}